package views

import "github.com/cloudwego/hertz/pkg/common/utils"

const (
	MIMETextHtmlUTF8 = "text/html; charset=utf-8"
)

var (
	SUCCESS   = ResultCode{sys: "G", code: "0000", msg: "ok"}
	SYS_ERROR = ResultCode{sys: "G", code: "1000", msg: "系统错误"}

	BAD_TOKEN = ResultCode{sys: "G", code: "1001", msg: "错误token"}
)

type OH = utils.H

func NewSuccessH[T any](data T) OH {
	return OH{
		"code": SUCCESS.GetResult(),
		"msg":  SUCCESS.GetMsg(),
		"data": data,
	}
}

func NewFailedH[T any](data T) OH {
	return OH{
		"code": SYS_ERROR.GetResult(),
		"msg":  SYS_ERROR.GetMsg(),
		"data": data,
	}
}

type ResultVo struct {
	Code string `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

func NewSuccess[T any](data T) *ResultVo {
	return &ResultVo{
		Code: SUCCESS.GetResult(),
		Msg:  SUCCESS.GetMsg(),
		Data: data,
	}
}

func NewFailed[T any](data T) *ResultVo {
	return &ResultVo{
		Code: SYS_ERROR.GetResult(),
		Msg:  SYS_ERROR.GetMsg(),
		Data: data,
	}
}

func NewFailedC[T any](c ResultCode, d T) *ResultVo {
	return &ResultVo{
		Code: c.GetResult(),
		Msg:  c.GetMsg(),
	}
}
